package com.powermanagertest;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class GetBitmap {

	/**
	 * ��������ͼ��Bitmap
	 * 
	 * @param url
	 * @return
	 * 
	 * @throws MalformedURLException
	 * @throws IOException
	 */
	public static Bitmap getBitmap(String url) throws IOException {
		Bitmap bitmap = null;
		InputStream is = null;
		try {
			is = getNetInputStream(url);
			bitmap = BitmapFactory.decodeStream(is);
		} finally {
			if (is != null)
				is.close();
		}
		return bitmap;
	}
	
	
	/**
	 * ����ļ���
	 * 
	 * @param urlStr
	 * @return
	 * 
	 * @throws MalformedURLException
	 * @throws IOException
	 */
	public static InputStream getNetInputStream(String urlStr)
			throws IOException {

		URL url = new URL(urlStr);
		URLConnection conn = url.openConnection();
		conn.connect();
		InputStream is = conn.getInputStream();
		return is;
	}
}
